<!DOCTYPE html>
<html lang="en-us" id="extr-page">
	<head>
		<meta charset="utf-8">
		<title>用户登录</title>
		<meta name="description" content="">
		<meta name="author" content="">
		<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
		
		<!-- #CSS Links -->
		<!-- Basic Styles -->
		<link rel="stylesheet" type="text/css" media="screen" href="static/plugin/bootstrap/css/bootstrap.min.css">
		<link rel="stylesheet" type="text/css" media="screen" href="static/css/elusive-icons.min.css">

		<!-- SmartAdmin Styles : Caution! DO NOT change the order -->
		<link rel="stylesheet" type="text/css" media="screen" href="static/css/smartadmin-production.min.css">
		<link rel="stylesheet" type="text/css" media="screen" href="static/css/smartadmin-skins.min.css">

		<!-- SmartAdmin RTL Support -->
		<link rel="stylesheet" type="text/css" media="screen" href="static/css/smartadmin-rtl.min.css"> 

		<!-- We recommend you use "your_style.css" to override SmartAdmin
		     specific styles this will also ensure you retrain your customization with each SmartAdmin update.
		<link rel="stylesheet" type="text/css" media="screen" href="static/css/your_style.css"> -->

		<!-- #FAVICONS -->
		<link rel="shortcut icon" href="static/img/favicon/favicon.ico" type="image/x-icon">
		<link rel="icon" href="static/img/favicon/favicon.ico" type="image/x-icon">

		<!-- #GOOGLE FONT -->
		<!-- 
		<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Open+Sans:400italic,700italic,300,400,700">
 		-->
		<!-- #APP SCREEN / ICONS -->
		<!-- Specifying a Webpage Icon for Web Clip 
			 Ref: https://developer.apple.com/library/ios/documentation/AppleApplications/Reference/SafariWebContent/ConfiguringWebApplications/ConfiguringWebApplications.html -->
		<link rel="apple-touch-icon" href="static/img/splash/sptouch-icon-iphone.png">
		<link rel="apple-touch-icon" sizes="76x76" href="static/img/splash/touch-icon-ipad.png">
		<link rel="apple-touch-icon" sizes="120x120" href="static/img/splash/touch-icon-iphone-retina.png">
		<link rel="apple-touch-icon" sizes="152x152" href="static/img/splash/touch-icon-ipad-retina.png">
		
		<!-- iOS web-app metas : hides Safari UI Components and Changes Status Bar Appearance -->
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		
		<!-- Startup image for web apps -->
		<link rel="apple-touch-startup-image" href="static/img/splash/ipad-landscape.png" media="screen and (min-device-width: 481px) and (max-device-width: 1024px) and (orientation:landscape)">
		<link rel="apple-touch-startup-image" href="static/img/splash/ipad-portrait.png" media="screen and (min-device-width: 481px) and (max-device-width: 1024px) and (orientation:portrait)">
		<link rel="apple-touch-startup-image" href="static/img/splash/iphone.png" media="screen and (max-device-width: 320px)">

	</head>
	
	<body class="animated fadeInDown">

		<header id="header">

			<div id="logo-group">
				<span id="logo"> <img src="static/img/logo_1.png" alt="irdstudio" style="height:30px" valign="top"> </span>
			</div>

		</header>

		<div id="main" role="main">

			<!-- MAIN CONTENT -->
			<div id="content" class="container">

				<div class="row">
					<div class="col-xs-12 col-sm-12 col-md-7 col-lg-8 hidden-xs hidden-sm">
						<h1 class="txt-color-red login-header-big">我的应用管理中心</h1>
						<div class="hero">

							<div class="pull-left login-desc-box-l">
								<h4 class="paragraph-header">It's Okay to be Smart. Experience the simplicity of SmartAdmin, everywhere you go!</h4>
								<div class="login-app-icons">
									<a href="javascript:void(0);" class="btn btn-danger btn-sm">Frontend Template</a>
									<a href="javascript:void(0);" class="btn btn-danger btn-sm">Find out more</a>
								</div>
							</div>
						</div>

					</div>
					<div class="col-xs-12 col-sm-12 col-md-5 col-lg-4">
						<div class="well no-padding">
							<form action="#" name="login-form" id="login-form" class="smart-form client-form">
								<header>
									用户登录
								</header>

								<fieldset>
									
									<section>
										<label class="label">用户名</label>
										<label class="input"> <i class="icon-append el el-user"></i>
											<input type="text" name="userId" id="userId">
											<b class="tooltip tooltip-top-right"><i class="el el-user txt-color-teal"></i> Please enter email address/username</b></label>
									</section>

									<section>
										<label class="label">密码</label>
										<label class="input"> <i class="icon-append el el-lock"></i>
											<input type="password" name="password" id="password">
											<b class="tooltip tooltip-top-right"><i class="el el-lock txt-color-teal"></i> Enter your password</b> </label>
										<div class="note">
											<!-- <a href="forgotpassword.html">忘记密码?</a> -->
										</div>
									</section>

									<section>
										<label class="checkbox">
											<input type="checkbox" name="remember" id="remember">
											<i></i>记住登录用户名</label>
									</section>
								</fieldset>
								<footer>
									<button type="button" class="btn btn-primary" onclick="doLoginCheck()">
										登录
									</button>
								</footer>
							</form>

						</div>
						<!-- 
						<h5 class="text-center"> - Or sign in using -</h5>
															
							<ul class="list-inline text-center">
								<li>
									<a href="javascript:void(0);" class="btn btn-primary btn-circle"><i class="fa fa-facebook"></i></a>
								</li>
								<li>
									<a href="javascript:void(0);" class="btn btn-info btn-circle"><i class="fa fa-twitter"></i></a>
								</li>
								<li>
									<a href="javascript:void(0);" class="btn btn-warning btn-circle"><i class="fa fa-linkedin"></i></a>
								</li>
							</ul>
						 -->
					</div>
				</div>
			</div>

		</div>

		<!--================================================== -->	

	    <!-- Link to Google CDN's jQuery + jQueryUI; fall back to local -->
	    <!--<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>-->
		<script> if (!window.jQuery) { document.write('<script src="static/js/libs/jquery-2.1.1.min.js"><\/script>');document.write('<script src="static/js/libs/jquery.cookie.min.js"><\/script>');} </script>
		
	    <!--<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js"></script>
		<script> if (!window.jQuery.ui) { document.write('<script src="static/js/libs/jquery-ui-1.10.3.min.js"><\/script>');} </script>-->

		<!-- IMPORTANT: APP CONFIG -->
		<script src="static/js/app.config.seed.js"></script>
		<script src="static/js/jsencrypt/jsencrypt.min.js"></script>

		<!-- JS TOUCH : include this plugin for mobile drag / drop touch events 		
		<script src="static/js/plugin/jquery-touch/jquery.ui.touch-punch.min.js"></script> -->

		<!-- BOOTSTRAP JS -->		
		<script src="static/plugin/bootstrap/js/bootstrap.min.js"></script>
		
		<!--[if IE 8]>
			
			<h1>Your browser is out of date, please update your browser by going to www.microsoft.com/download</h1>
			
		<![endif]-->

		<!-- MAIN APP JS FILE -->
		<script src="static/js/app.seed.js"></script>

	</body>
	<script>
		$(function() {
			if($.cookie('signRemember') == 'true') {
				// 自动设置是否记住用户名
				$("#remember").attr("checked", true);	
				// 自动设置用户名
				$("#userId").val($.cookie('signUserId'));	
			} else {
				$("#remember").attr("checked", false);	
			}
		});
		
		var bizUrl = "index.html";
		function doLoginCheck(){
			if($("#userId").val() == ''){
				alert('请输入用户名!');
				return;
			}
			if($("#password").val() == ''){
				alert('请输入密码!');    
				return;
			}
			
			//设置是否记住用户名
			$.cookie('signRemember', $("#remember").is(":checked"), { expires: 30 });
			//记住用户名
			if($("#remember").val()) {
				$.cookie('signUserId', $("#userId").val(), { expires: 7 });
			} else {
				$.removeCookie('signUserId');
			}
			//var param = $('#login-form').serialize();
			//$(location).attr('href', bizUrl);
			//return;

			var getRSAPublicKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDAYwQ81rc1KW8tTYpxrLS3ArVxB40otmbWyXwgDQRkLsCuQKiq6KZgAM/8sJuI12S1JVOXnMu5d420vKFFS/+Ibz4TxqjhLmgownaguMTbAGBzIPvfN5lL52mDmm/CvKu2YPCFvZV8YulNTCexvuj7OiWRUXpAbaQqu5tPOjGytQIDAQAB";
			var encrypt = new JSEncrypt();
			encrypt.setPublicKey(getRSAPublicKey);
			var jsonData = {
				usercode : $("#userId").val(),
				password : encrypt.encrypt($('#password').val())
			};
			$.ajax({
				type : "POST",
				url : "api/oauth/token",
				contentType : "application/json;charset=utf-8",
				data : JSON.stringify(jsonData),
				dataType : "json",
				async : false,
				success : function(data) {
					try {
						var jsonstr = eval(data);
						var flag = jsonstr.success && jsonstr.rows;
						if (flag) {
							
							//$(location).attr('href', bizUrl);
							//$(window).attr('location',bizUrl);
							//$(location).prop('href', bizUrl);
							//window.location.href = bizUrl;
							//window.event.returnValue = false;
							//top.location.href = bizUrl;
							
							// 获取会话信息并保存到cookies中
							$.ajax({
								type : "POST",
								url : "api/session/info",
								contentType : "application/json;charset=utf-8",
								dataType : "json",
								async : false,
								success : function(sessionData) {
									var userId = sessionData.rows.userId;
									var userName = sessionData.rows.userName;
									$.cookie('signUserId', userId, { expires: 1 });
									$.cookie('signUserName', userName, { expires: 1 });
								}
							});
							
							// 登录成功,跳转到业务系统
							$(location).attr('href', bizUrl);
							
						} else {
							alert(jsonstr.message);
						}
					} catch (e) {
						alert(e);
					}
				},
				error : function(XMLHttpRequest, textStatus, errorThrown) {
					alert("登录失败，请重试或联系管理员！");
				}
			});
		}
		$(document).keypress(function(e) {
			// 回车键事件 
			if (e.which == 13) {
				if ($("#userId").val() != '' && $("#password").val() != '') {
					doLoginCheck();
				} else if ($("#userId").val() != '') {
					$("#password")[0].focus();
				}

			}
		});
	</script>	
</html>